package Scrap;


public class poly {
	public static void main(String arg[])
	{
		int x[]={-2,2,1,3,3,0,-1,-1};
		int y[]={0,0,1,4,-2,3,2,2,-1,-1};
		pol(x,y);
	}
	public static void pol(int x[],int y[])
	{ 
		int n1=x.length-2;
		int n2=y.length-2;
		int k=0;

		int len=Math.max(n1,n2);
		int arr[]=new int[len];
		int sum[] = new int[len];
		for(int i=0;i<=n1;i=i+2)
		{
			for(int j=0;j<n2;j=j+2)
			{
				if(x[i+1]==y[j+1])
				{
					sum[k]=x[i]+y[j];
					//System.out.println("sum"+sum[k]);
					System.out.print(sum[k]+"x^"+x[i+1]+" + ");
					arr[k]=y[j+1];
					k++;
				}
			}
		}
		for(int j=0;j<n2;j++)
		{
			if(y[j+1]!=arr[k])
			{
				System.out.print(y[j]+"x^"+y[j+1]);
			}

		}
	}
}
